<template>
	<block v-if="display">
		<view class="box" v-if="data.data !== undefined && data.data!== null && data.data .length>0">
			<block v-if="sign == 1 || sign == 5">
				<u-sticky style="margin-bottom: 40rpx;">
					<u-search placeholder="输入标题搜索" v-model="search" @search="_search" @clickIcon="_search"
						@custom="_search"></u-search>
				</u-sticky>
			</block>
			<block v-if="sign == 1">
				<u-collapse :accordion="true" :border="false" @open="open($event)">
					<u-collapse-item :title="item.title" :value="item.create_time_text" :isLink="false"
						v-for="(item,index) in data.data" :key="index" :name="index"
						style="margin-top: 20rpx;border: 1px #eeeeee solid;">
						<view class="info_list">
							<view class="info_item">产品：
								<view class="">
									<text>{{product}}</text>
								</view>
							</view>
							<view class="info_item">费率：
								<view class="">
									<text v-for="(list,nmb) in item.rate" :key="nmb">[{{list.name}}]</text>
								</view>
							</view>
							<view class="info_item">交易类型：
								<view class="">
									<text v-for="(list,nmb) in item.tran" :key="nmb">[{{list.name}}]</text>
								</view>
							</view>
							<view class="info_item">卡类型：
								<view class="">
									<text v-for="(list,nmb) in item.card" :key="nmb">[{{list.name}}]</text>
								</view>
							</view>
							<view class="info_item">收款方式：
								<view class="">
									<text v-for="(list,nmb) in item.channel" :key="nmb">{{list.name}}</text>
								</view>
							</view>
						</view>
						<view class="operating">
							<view class="fize" style="background-color: #3c9cff;" @click="_setup(item.id)">设置</view>
							<view class="fize" style="background-color: #f4450b;" @click="_delete(item.id)">删除</view>
						</view>
					</u-collapse-item>
				</u-collapse>
			</block>
			<block v-else-if="sign == 2">
				<u-collapse :accordion="true" :border="false" @open="open($event)">
					<u-collapse-item :title="item.title" :value="item.create_time_text" :isLink="false"
						v-for="(item,index) in data.data" :key="index" :name="index"
						style="margin-top: 20rpx;border: 1px #eeeeee solid;">
						<view class="info_list">
							<view class="info_item">产品：
								<view class="">
									<text>{{product}}</text>
								</view>
							</view>
							<view class="info_item">费率：
								<view class="">
									<text v-for="(list,nmb) in item.rate" :key="nmb">[{{list.name}}]</text>
								</view>
							</view>
							<view class="info_item">交易类型：
								<view class="">
									<text v-for="(list,nmb) in item.tran" :key="nmb">[{{list.name}}]</text>
								</view>
							</view>
							<view class="info_item">卡类型：
								<view class="">
									<text v-for="(list,nmb) in item.card" :key="nmb">[{{list.name}}]</text>
								</view>
							</view>
							<view class="info_item">收款方式：
								<view class="">
									<text v-for="(list,nmb) in item.channel" :key="nmb">{{list.name}}</text>
								</view>
							</view>
							<view class="info_item">天数限制：
								<view class="">
									<text>{{item.day_limit}}</text>
								</view>
							</view>
							<view class="info_item">刷卡金额：
								<view class="">
									<text>{{item.money}}</text>
								</view>
							</view>
							<view class="info_item">奖励金额：
								<view class="">
									<text>{{item.reward}}</text>
								</view>
							</view>
						</view>
						<view class="operating">
							<view class="fize" style="background-color: #f4450b;" @click="_delete(item.id)">删除</view>
						</view>
					</u-collapse-item>
				</u-collapse>
			</block>
			<block v-else-if="sign == 3">
				<u-collapse :accordion="true" :border="false" @open="open($event)">
					<u-collapse-item :title="item.title" :value="item.create_time_text" :isLink="false"
						v-for="(item,index) in data.data" :key="index" :name="index"
						style="margin-top: 20rpx;border: 1px #eeeeee solid;">
						<view class="info_list">
							<view class="info_item">产品：
								<view class="">
									<text>{{product}}</text>
								</view>
							</view>
							<view class="info_item">奖励金额：
								<view class="">
									<text>{{item.reward}}</text>
								</view>
							</view>
						</view>
						<view class="operating">
							<view class="fize" style="background-color: #f4450b;" @click="_delete(item.id)">删除</view>
						</view>
					</u-collapse-item>
				</u-collapse>
			</block>
			<block v-else-if="sign == 4">
				<u-collapse :accordion="true" :border="false" @open="open($event)">
					<u-collapse-item :title="item.title" :value="item.create_time_text" :isLink="false"
						v-for="(item,index) in data.data" :key="index" :name="index"
						style="margin-top: 20rpx;border: 1px #eeeeee solid;">
						<view class="info_list">
							<view class="info_item">产品：
								<view class="">
									<text>{{product}}</text>
								</view>
							</view>
							<view class="info_item">费率：
								<view class="">
									<text v-for="(list,nmb) in item.rate" :key="nmb">[{{list.name}}]</text>
								</view>
							</view>
							<view class="info_item">交易类型：
								<view class="">
									<text v-for="(list,nmb) in item.tran" :key="nmb">[{{list.name}}]</text>
								</view>
							</view>
							<view class="info_item">卡类型：
								<view class="">
									<text v-for="(list,nmb) in item.card" :key="nmb">[{{list.name}}]</text>
								</view>
							</view>
							<view class="info_item">收款方式：
								<view class="">
									<text v-for="(list,nmb) in item.channel" :key="nmb">{{list.name}}</text>
								</view>
							</view>
							<view class="info_item">天数限制：
								<view class="">
									<text>{{item.day_limit}}</text>
								</view>
							</view>
							<view class="info_item">刷卡金额：
								<view class="">
									<text>{{item.money}}</text>
								</view>
							</view>
							<view class="info_item">奖励金额：
								<view class="">
									<text>{{item.reward}}</text>
								</view>
							</view>
						</view>
						<view class="operating">
							<view class="fize" style="background-color: #f4450b;" @click="_delete(item.id)">删除</view>
						</view>
					</u-collapse-item>
				</u-collapse>
			</block>
			<block v-else>
				<u-collapse :accordion="true" :border="false">
					<u-collapse-item :title="item.title" :value="item.create_time_text" :isLink="false"
						v-for="(item,index) in data.data" :key="index" :name="index"
						style="margin-top: 20rpx;border: 1px #eeeeee solid;">
						<view class="operating">
							<view class="fize" style="background-color: #8ee1b2;" @click="_info(item.id)">详情</view>
							<view class="fize" style="background-color: #f4450b;" @click="_delete(item.id)">删除</view>
						</view>
					</u-collapse-item>
				</u-collapse>
			</block>
			<!-- <u-swipe-action-item class="halve_list" :options="options2" v-for="(item,index) in data.data"
					:key="index" @click="halve_info($event,item.id,sign)">
					<view class="halve_box">
						<view class="halve_tit">
							<text>{{item.title}}
							</text>
							<text>{{item.create_time_text}}</text>
						</view>
						<view class="halve_bg">
							<view class="bg"></view>
						</view>
					</view>
				</u-swipe-action-item> -->
			<!-- <u-swipe-action v-else>
				<u-swipe-action-item class="halve_list" :options="sign ==5?options3:options1 "
					v-for="(item,index) in data.data" :key="index" @click="halve_info($event,item.id,sign)">
					<view class="halve_box">
						<view class="halve_tit">
							<text>{{item.title}}
							</text>
							<text>{{item.create_time_text}}</text>
						</view>
						<view class="halve_bg">
							<view class="bg"></view>
						</view>
					</view>
				</u-swipe-action-item>
			</u-swipe-action> -->
		</view>
		<u-empty v-else mode="list" icon="/static/Empty/data_null.png">
		</u-empty>
	</block>
</template>

<script>
	export default {
		data() {
			return {
				data: {},
				sign: null, //上一个页面带过来的标识
				urls: '',
				NavTitle: '',
				display: false,
				delete_url: '',
				page: 1,
				bottom: true,
				search: '',
				product: null
			}
		},
		onLoad(options) {
			this.sign = options.sign
			switch (this.sign) {
				case '1':
					//分润设置
					this.urls = 'setting/getProfitList'
					this.delete_url = 'setting/deleteProfit'
					break
				case '2':
					//返现设置
					this.urls = 'setting/getCashList'
					this.delete_url = 'setting/deleteCash'
					break
				case '3':
					//流量卡设置
					this.urls = 'setting/getFlowList'
					this.delete_url = 'setting/deleteFlow'
					break
				case '4':
					//达标设置
					this.urls = 'setting/getStandardList'
					this.delete_url = 'setting/deleteStandard'
					break
				case '5':
					//政策设置
					this.urls = 'setting/getPolicyList'
					this.delete_url = 'setting/deletePolicy'
					break
			}
		},
		onShow() {
			this._rate()
		},
		//添加
		onNavigationBarButtonTap(e) {
			uni.navigateTo({
				url: '/pages/index/rate_setup/rate_halve/add_halve?sign=' + this.sign
			})
		},
		//下拉刷新
		onReachBottom() {
			if (this.bottom == true) {
				this.page += 1
				this._rate()
			}
		},
		methods: {
			open(e) {
				this.product = this.data.data[e].product.name
			},
			_search() {
				this._rate()
			},
			async _rate() {
				uni.showLoading({
					title: '加载中'
				});
				const userinfo = uni.getStorageSync('userinfo');
				const {
					data: res
				} = await this.$myHttp({
					url: this.urls,
					data: {
						page: this.page,
						page_size: 15,
						search: this.search
					},
					header: {
						'token': userinfo.token
					},
				});
				this.NavTitle = res.msg
				uni.setNavigationBarTitle({
					title: this.NavTitle
				});
				this.display = true
				if (res.code == 1) {
					if (res.data.data !== undefined && res.data.data !== null && res.data.data.length >
						0) {
						if (this.page == 1) {
							this.data = res.data
							uni.hideLoading()
						} else {
							this.data.data = [...this.data.data, ...res.data.data]
							uni.hideLoading()
						}
					} else {
						uni.hideLoading()
						this.bottom = false
					}
				} else {
					uni.showToast({
						title: res.msg,
						duration: 1000,
						icon: "none"
					});
					this.bottom = false
				}
			},
			//设置
			_setup(id){
				uni.navigateTo({
					url: '/pages/index/rate_setup/rate_halve/halve_setup?id=' + id
				})
			},
			//详情
			_info(id){
				uni.navigateTo({
					url: '/pages/index/rate_setup/rate_halve/policy_info?id=' + id
				})
			},
			//删除
			_delete(id) {
				let _this = this
				uni.showModal({
					title: '提示',
					content: '是否删除',
					success: function(res) {
						if (res.confirm) {
							_this.delete_qr(id)
						}
					}
				});
			},
			async delete_qr(id) {
				uni.showLoading({
					title: '加载中'
				});
				const userinfo = uni.getStorageSync('userinfo');
				const {
					data: res
				} = await this.$myHttp({
					url: this.delete_url,
					data: {
						id: id
					},
					header: {
						'token': userinfo.token
					},
				});
				let _this = this
				if (res.code == 1) {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 3000,
						success() {
							setTimeout(() => {
								_this.$router.go(0)
							}, 2000)
						}
					})
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 3000
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		padding: 30rpx;
		box-sizing: border-box;
	}

	.operating {
		display: flex;
		justify-content: space-between;

		.fize {
			color: #fff;
			padding: 10rpx 50rpx;
			border-radius: 15rpx;
			margin-top: 30rpx;
		}
	}

	.info_list {

		.info_item {
			margin-top: 15rpx;
			font-size: 28rpx;
			display: flex;
			justify-content: space-between;

			view {
				width: 70%;
				text-align: right;
				display: flex;
				justify-content: flex-end;
			}
		}
	}
</style>